<?php
/**
 * @description 网易云服务器API接口
 * @author 时
 */
namespace wyiyun;
use Prophecy\Exception\Exception;
class Common
{
   private static $_instance;
    private $Appkey;
 // 开发者平台分配的appkey
    private $AppSecret;
 // 随机数（最大长度128个字符）
    private $accid;

    private $props;

    private $icon;

    private $toekn;

    private $Nonce;

    private $data = [];

    private $string;

    private $url;

    private $character = [
        '0',
        '1',
        '2',
        '3',
        '4',
        '5',
        '6',
        '7',
        '8',
        '9',
        'a',
        'b',
        'c',
        'd',
        'e',
        'f'
    ];

    private $CurTime;
 // 当前UTC时间戳，从1970年1月1日0点0 分0 秒开始到现在的秒数(String)
    private $CheckSum;
 // SHA1(AppSecret + Nonce + CurTime),三个参数拼接的字符串，进行SHA1哈希计算，转化成16进制字符(String，小写)
    /**
     *
     * @return the $Appkey
     */
    public function getAppkey()
    {
        return $this->Appkey;
    }

    /**
     *
     * @return the $AppSecret
     */
    public function getAppSecret()
    {
        return $this->AppSecret;
    }

    /**
     *
     * @param field_type $Appkey            
     */
    public function setAppkey($Appkey)
    {
        $this->Appkey = $Appkey;
    }

    /**
     *
     * @param field_type $AppSecret            
     */
    public function setAppSecret($AppSecret)
    {
        $this->AppSecret = $AppSecret;
    }

    public function __construct($appkey, $appsecret)
    {
        $this->Appkey =$appkey;
        $this->AppSecret =$appsecret;
        $this->Nonce = $this->get_nums();
        // $this->string=$string;
        // $this->CurTime=(string)time();
        // $this->CheckSum=$this->checksum();
    }
   /**
    * 
    * @return string 返回随机生成的字符串
    * @author sj@qq.com
    */
    public function get_nums()
    {
        $key = rand(0, 15);
        $str = md5($this->character[$key]);
        $str = substr($str, 0, 16);
        return md5($str);
    }
/**
 * 
 * @return string 返回网易云随机生成的秘钥
 */
    function checksum()
    {
        
        $this->CurTime = time();
        $str = $this->AppSecret . $this->Nonce . $this->CurTime;
        $str = sha1($str);
        return $str;
    }

    /**
     * POST请求方法
     */
    private function Request()
    {
        $this->CheckSum = $this->checksum();
        $head = array();
        
        $head[] = "AppKey:$this->Appkey";
        $head[] = "Nonce:$this->Nonce";
        $head[] = "CurTime:$this->CurTime";
        $head[] = "CheckSum:$this->CheckSum";
        // var_dump($head);
        $head[] = "Content-Type: application/x-www-form-urlencoded";
        // var_dump($head);
        // $head=['User-Agent: Mozilla/5.0 (Windows NT 5.2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36','X-FORWARDED-FOR:154.125.25.15', 'CLIENT-IP:154.125.25.15'];
        $ch = curl_init($this->url);
        curl_setopt($ch, CURLOPT_HEADER, false);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $head);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $this->string);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
        $data = curl_exec($ch);
        curl_close($ch);
        return $data;
    }
    /**
     * @description 发送post请求
     * @return string 返回请求网易云数据
     */
    private function Request2()
    {
        $this->CheckSum = $this->checksum();
        $head = array();
        $head[] = "CheckSum:$this->CheckSum";
        $head[] = "AppKey:$this->Appkey";
        $head[] = "Nonce:$this->Nonce";
        $head[] = "CurTime:$this->CurTime";
        // var_dump($head);
        $head[] = "Content-Type: application/x-www-form-urlencoded";
        // var_dump($head);
        // $head=['User-Agent: Mozilla/5.0 (Windows NT 5.2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36','X-FORWARDED-FOR:154.125.25.15', 'CLIENT-IP:154.125.25.15'];
        $ch = curl_init($this->url);
        curl_setopt($ch, CURLOPT_HEADER, false);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $head);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $this->string);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
        $data = curl_exec($ch);
        curl_close($ch);
        return $data;
    }
/**
 * @description GET 请求
 * @return mixed 
 */
    private function get()
    {
        $head = [
            'User-Agent: Mozilla/5.0 (Windows NT 5.2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36',
            'X-FORWARDED-FOR:154.125.25.15',
            'CLIENT-IP:154.125.25.15'
        ];
        $ch = curl_init($this->url);
        curl_setopt($ch, CURLOPT_HEADER, false);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $head);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
        $data = curl_exec($ch);
        curl_close($ch);
        return $data;
    }
/**
 * @description 同步网易云账号
 * @param string  $username  网易云通信ID，最大长度32字符必须保证一个 必须填写
 * @param string  $nickname  网易云通信ID昵称，最大长度64字符，用来PUSH推送 时显示的昵称 可选
 * @param string  $props     son属性，第三方可选填，最大长度1024字符
 * @param string  $icon      网易云通信ID头像URL，第三方可选填，最大长度1024
 * @param string  $token     网易云通信ID可以指定登录token值，最大长度128字符 并更新，如果未指定，会自动生成token
 * 
 * @return null;
 */
    public function CreateId($username,$nickname="",$icon="",$props="",$token="")
    {
        // 这里accid是网易云唯一的标识 accid name 组合根据用户注册的用户账号和昵称进行作为accid 这个是账号,name是昵称
        $this->url = "https://api.netease.im/nimserver/user/create.action";
        $this->string = "accid=$username&name=$nickname"."&icon=".$icon;
        //成功返回200 失败返回 已经注册过返回 错误请求 
        //这里返回的接口的accid token是唯一的 所以这里操作数据库
        try {
            $data = $this->Request();
            $data = json_decode($data);
            
            if ($data->code == 200) {
                // 如果请求的正确返回tooken
                return $data->info->token;
            } else {
                sleep(5);
                $this->CreateId($username,$nickname);
            }
        } catch (Exception $e) {
            print($e->getMessage());
        }
    }
    
    /**
     * @description 同步网易账号第二版
     * @return mixed 返回json字符串和相应的状态吗
     * @category 用于用户账号同步 如果没有就添加 如果有了就不变返回相应的json
     * 
     */
    public function syctoaccount($user_id)
    {
    try 
    { 
         $this->url = "https://api.netease.im/nimserver/user/create.action";
         $this->string="accid=$user_id";
         $data=$this->Request();
         return $data;
    }catch (\think\Exception $e)
    {
       throw  new \think\Exception();
    }
    }
    
    /**
     * 检查用户是否已经注册网易云账号
     * @param string $account 网易云acid
     * @return string 如果用户已经注册返回 json {'msg'=>'register'}
     */
    public function check_accid($account)
    {
      try {
          $this->url = "https://api.netease.im/nimserver/user/create.action";
          $this->string="accid=$account";
          $data=$this->Request();
          $data_arr=json_decode($data,true);
          $code=isset($data_arr['code'])?$data_arr['code']:"";
          $desc=isset($data_arr['desc'])?$data_arr['desc']:"";
          if($desc=='already register'&&$code=='414')
          {
          return  json_encode(array('msg'=>'register'));  
          }
      }catch (Exception $e){
          throw new \think\Exception();
      }
    }
/**
 * 
 * @param string  $account 网易云id
 * @return string 返回json字符串 传递相应存在accid 并且更新不返回tooken
 */
    public function UpdateId($account)
    {
        $this->url = "https://api.netease.im/nimserver/user/update.action";
        $this->string = "accid=$account";
        try {
            $data = $this->Request();
            $data = json_decode($data);
            $arr = array(
                "status" => "sucess"
            );
            if ($data->code == 200) {
                return json_encode($arr);
            }else {
                return '{"desc":"not register"}';
            }
        } catch (Exception $e) {
            print($e->getMessage());
        }
    }
    /**
     * @description: 一般用于网易云通信ID修改密码，找回密码或者第三方有需求获取新的token。
     * @param string $account 网易云账号 
     * @return string $data   .webserver更新网易云通信ID的token，同时返回新的token；
     */
    public function refreshToken($account)
    {
        $this->url = "https://api.netease.im/nimserver/user/refreshToken.action";
        $this->string = "accid=$account";
        // 这个更新是要进行验证是否已经创建过之后进行更新
        // 所以在外面调用的时候进行根据返回的数组过后isset($arr)有的话并且不为空 Null ""
        // 说明之前已经创建 所以这个创建过后要将 token保存到全局变量中 seesion 保存到服务器中
        // 这个是用户登录的时候 之前我们的服务器进行返回服务器的保存的token
        try {
            $data = $this->Request();
            $data = json_decode($data);
            if ($data->code == 200) {
                return $data;
            }else {
                return '{"desc":"not register"}';
            }
        } catch (Exception $e) {
            print ($e->getMessage()) . $e->getTrace();
        }
    }
    /**
     * 
     * @param string $account 网易云账号
     * 用户禁用网易云账号
     * @return string $res
     */
    public function block($account)
    {
        //这个账号是我们服务器登录过后将其$account $nickname保存到seesion中的所以
        //seesion_start();$account=$_SESSION['account'] $nickname=$_SESSION['nickname'];
        //$account=isset($_SESSION)?(isset($_SEESION['account']?$_SESSION['account']:""):"";
        //就是将这个用户的网易ID禁用
        $this->url = "https://api.netease.im/nimserver/user/block.action";
        // needkick String 否 是否踢掉被禁用户，true或false，默认false
        // cid String 是 网易云通信ID，最大长度32字符，必须保证一个APP内唯一
        $this->string = "accid=$account";
        try {
            $data_str = $this->Request();
            $data = json_decode($data);
            $arr = array(
                "staus" => "sucess"
            );
            if ($data->code == 200) {
                return json_encode($arr);
            }else {
                return $data_str;
            }
        } catch (Exception $e) {
            print($e->getMessage());
        }
    }
    
    /**
     * 
     * @param string $account 网易云账号
     *  解禁网易云通信ID
     *  @return string $data 
     */
    public function unblock($account)
    {
        $this->url = "https://api.netease.im/nimserver/user/unblock.action";
        $this->string = "accid=$account";
        try {
            $data_str = $this->Request();
            $data = json_decode($data);
            $arr = array(
                "staus" => "sucess"
            );
            if ($data->code == 200) {
                return json_encode($arr);
            }else {
                return $data_str;
            }
        } catch (Exception $e) {
            print($e->getMessage());
        }
    }
    /**
     *  创建聊天室测试demo
     *  @param array $options 创建教室参数数组
     *  @return string $data
     */
   
    public function CreateChatrom($options){
        //$conifg=require 'chatrom.php';
        //这些聊天室的信息都是从前端异步传递post过来的数据
        $this->url="https://api.netease.im/nimserver/chatroom/create.action";
      
        $this->string="name=".$options['name']."&announcement=".$options['announcement']."&broadcasturl=".$options['broadcasturl']."&creator=".$options['creator'];
        try {
            $data_str=$this->Request2();
            $data=json_decode($data_str);
            //var_dump($data);
            //这里如果请求正常将整个对象返回json格式
            if($data->code==200){
                return $data_str;
            }else {
                return '{"ChatRoom create failed"}';
            }
        }catch (Exception $e){
            print ($e->getMessage());
        }
        //name=$conifg['ChatromCreate']['name']&announcement=$conifg['ChatromCreate']['announcement']&broadcasturl=$conifg['ChatromCreate']['broadcasturl']&creator=$conifg['ChatromCreate']['creator']
    }
    /**
     * 查询教室信息demo
     * @param array $options 查询教室信息参数
     * @return json $res
     */
    public function FetchChatInfo($options){
        $data_str=$this->CreateChatrom($options);
        $data_obj=json_decode($data_str);
        $roomid=$data_obj->chatroom->roomid;
        $this->url="https://api.netease.im/nimserver/chatroom/get.action";
        $this->string="roomid=".$roomid."&needOnlineUserCount=".true;
        try {
            $data_str=$this->Request2();
            $data=json_decode($data_str);
            if($data->code==200){
                return $data_str;
            }else {
                return '{"msg:""fetc failed"}';
            }
            
        }catch (Exception $e){
            print ($e->getMessage());
        }
    }
   
    /**
     * 获取聊天室信息(不创建自动获取信息)
     * @param string  $roomid 教室ID
     * @throws \think\Exception
     * @return string
     */
    public function FetchChatInfos($roomid)
    {
        $this->url="https://api.netease.im/nimserver/chatroom/get.action";
        $this->string="roomid=".$roomid."&needOnlineUserCount=".true;
       
        try 
        {
            $data_str=$this->Request2();
            $data=json_decode($data_str,true);
            
            if($data['code']==200)
            {
               return $data_str; 
            }else {
                throw new \think\Exception('fetch failed');
            }
            
        }catch (\think\Exception $e)
        {
            print ($e->getMessage());
        }
    }
    
   /**
    * 更新教室信息
    * @param array $options 更新教室参数数组
    * @return string $data_str
    */
    public function UpdateChatRom($options){
        $this->url="https://api.netease.im/nimserver/chatroom/update.action";
        $this->string="roomid=".$options['roomid']."&name=".$options['name']."&announcement=".$options['announcement']."&broadcasturl=".$options['broadcasturl']."&ext=".$options['ext'];
        try {
            
            $data_str=$this->Request2();
           
            $data_obj=json_decode($data_str);
            if($data_obj->code==200){
                return $data_str;
            }else{
                return $data_str;
            }
        }catch (Exception $e){
            print ($e->getMessage());
        }
    }
    /**
     * 
     * @param array $options 修改教室参数
     * @return string $data_str
     */
    public function closestate($options){
        
        $this->url="https://api.netease.im/nimserver/chatroom/toggleCloseStat.action";
        $this->string="roomid=".$options['roomid']."&operator=".$options['operator']."&valid=".$options['valid'];
        
        try {
            //这里默认的后台开启
          
            $data_str=$this->Request2();
           return $data_str;
           
        }catch (Exception $e){
            print ($e->getMessage());
        }
        
    }
    //设置聊天室内用户角色
    public function MemberRole($options){
        $this->url="https://api.netease.im/nimserver/chatroom/setMemberRole.action";
        $this->string="roomid=".$options['roomid']."&operator=".$options['operator']."&target=".$options['target']."&opt=".$options['opt']."&optvalue=".$options['optvalue'];
        
        try {
            $data_str=$this->Request2();
          
            $data_obj=json_decode($data_str);
           if($data_obj->code==200){
               return $data_str;
           }else {
               return $data_str;
           }
        }catch (Exception $e){
            print ($e->getMessage());
        }
    }
    /**
     * @param array $options 请求地址参数
     * @return string 相应的json请求地址路径
     * @param string roomid 聊天室id
     * @param string accid 进入聊天室的账号
     * @param int clienttype 1:weblink; 2:commonlink, 默认1
     */
    public function requestAddr($options){
        $this->url="https://api.netease.im/nimserver/chatroom/requestAddr.action";
        $this->string="roomid=".$options['roomid']."&accid=".$options['accid']."&clienttype=".$options['clienttype'];
//         var_dump($this->string);
//         die;
      try {
          $res=$this->Request2();
          return $res;
      }catch (\think\Exception $e){
          die($e->getMessage());
      }
        
        
    }
   
    
    
    public static function Instance(){
        if(self::$_instance instanceof  self){
            self::$_instance=new self();
        }
        return self::$_instance;
    }
    public function sendMsg($options)
    {
        $this->url="https://api.netease.im/nimserver/chatroom/sendMsg.action";
        $this->string="roomid=".$options['roomid'].
        "&fromAccid=".$options['fromAccid'].
        "&msgType=".$options['msgType']
        ."&attach=".$options['attach']
        ."&msgId=".uniqid().md5(rand(1,1000000000));
        ;
        try 
        {
            $res=$this->Request2();
            return $res;
        }catch (\think\Exception $e)
        {
            
        }
    }
    /**
     * 设置临时禁言状态
     * @param array $options
     * @return string
     */
    public function temporaryMute($options)
    {
        $this->url="https://api.netease.im/nimserver/chatroom/temporaryMute.action";
        $this->string="roomid=".$options['roomid'].
        "&operator=".$options['operator'].
        "&target=".$options['target']
        ."&muteDuration=".$options['muteDuration']
        ."&notifyExt=".$options['notifyExt']
        ;
        try
        {
            $res=$this->Request2();
            return $res;
        }catch (\think\Exception $e)
        {
    
        }
    }
    //设置聊天室整体禁言状态（仅创建者和管理员能发言）
    public function muteRoom($options)
    {
        $this->url="https://api.netease.im/nimserver/chatroom/muteRoom.action";
        $this->string="roomid=".$options['roomid'].
        "&operator=".$options['operator'].
        "&mute=".$options['mute']
        ;
     
        try
        {
            $res=$this->Request2();
            return $res;
        }catch (\think\Exception $e)
        {
       print ($e->getMessage());
        }
    }
    /**
     * 接口描述:分页获取成员列表
     * 
     * @param array $options
     * roomid long  聊天室id
     * type   int   需要查询的成员类型,0:固定成员;1:非固定成员;2:仅返回在线的固定成员
     * endtime long 单位毫秒，按时间倒序最后一个成员的时间戳,0表示系统当前时间
     * limit   long  返回条数，<=100
     * @return string $res
     */
    
    public function membersByPage($options)
    {
        $this->url="https://api.netease.im/nimserver/chatroom/membersByPage.action";
        $this->string="roomid=".$options['roomid'].
        "&type=".$options['type'].
        "&endtime=".$options['endtime'].
        "&limit=".$options['limit']
        ;
         
        try
        {
            $res=$this->Request2();
            return $res;
        }catch (\think\Exception $e)
        {
            print ($e->getMessage());
        }
    }
    /**
     * 批量获取在线成员信息
     */
    public function queryMembers($options)
    {
        $this->url="https://api.netease.im/nimserver/chatroom/queryMembers.action";
        $this->string="roomid=".$options['roomid'].
        "&accids=".$options['accids'];
    
        try
        {
            $res=$this->Request2();
            return $res;
        }catch (\think\Exception $e)
        {
            print ($e->getMessage());
        }
    }
    /**
     * 变更聊天室内的角色信息
     */
    public function updateMyRoomRole($options)
    {
        $this->url="https://api.netease.im/nimserver/chatroom/updateMyRoomRole.action";
        $this->string="roomid=".$options['room_id'].
        "&accid=".$options['accid'].
        "&save=".$options['save'].
        "&nick=".$options['nick'].
        "&avator=".$options['avator'];
    //var_dump($this->string);
        try
        {
            $res=$this->Request2();
            return $res;
        }catch (\think\Exception $e)
        {
            print ($e->getMessage());
        }
    }
    /***
     * 往聊天室有序队列中新加或更新元素
     * @param array $options
     * 接口描述
     * 往聊天室有序队列中新加或更新元素
     * 参数说明
     * @param long roomid 聊天室id
     * @param string key elementKey,新元素的UniqKey,长度限制128字符
     * @param string value lementValue,新元素内容，长度限制4096字符   
     * @return string $res  
     */
    public function queueOffer($options)
    {
        $this->url="https://api.netease.im/nimserver/chatroom/queueOffer.action";
        $this->data='roomid='.$options['roomid'].
        '&key='.$options['key'].
        '&value'.$options['value'];
           try 
           {
            $res=$this->Request2();
            return $res;
           }catch (\think\Exception $e)
           {
           dump($e->getMessage());
           }
    }
    /**
     * 从队列中取出元素
     * 接口描述
     * 从队列中取出元素
     * @param array $options
     * @param long roomid 聊天室id
     * @param string key 目前元素的elementKey,长度限制128字符，不填表示取出头上的第一个
     * @return string $res
     */
    public function queuePoll($options)
    {
        $this->url="https://api.netease.im/nimserver/chatroom/queuePoll.action";
        $this->string="roomid=".$options['roomid']."&key=".$options['key'];
        try 
        {
          $res=$this->Request2();
          return $res;
        }catch (\think\Exception $e)
        {
            dump($e->getMessage());
        }
    }
    /**
     * 排序列出队列中所有元素
     * 接口描述
     * 排序列出队列中所有元素
     * @param array $options
     * @param long roomid 聊天室id
     * @return string $res
     */
    public function queueList($options)
    {
        $this->url="https://api.netease.im/nimserver/chatroom/queueList.action";
        $this->string="roomid=".$options['roomid'];
        try 
        {
          $res=$this->Request2();
          var_dump($res);
          return $res;
        }catch (\think\Exception $e)
        {
            dump($e->getMessage());
        }
    }
    /**
     * 删除清理整个队列
     * 接口描述
     * 删除清理整个队列
     * @param array $options
     * @param long roomid 聊天室id
     * @return string $res
     */
    public function queueDrop($options)
    {
        $this->url="https://api.netease.im/nimserver/chatroom/queueDrop.action";
        $this->string="roomid=".$options['roomid'];
        try
        {
            $res=$this->Request2();
            return $res;
        }catch (\think\Exception $e)
        {
            dump($e->getMessage());
        }
    }
    /**
     * 初始化队列
     * 接口描述
     * 初始化队列
     * @param array $options
     * @param long roomid 聊天室id
     * @param long sizeLimit 队列长度限制，0~1000
     * @return string $res
     */
    public function queueInit($options)
    {
        $this->url="https://api.netease.im/nimserver/chatroom/queueInit.action";
        $this->string="roomid=".$options['roomid']."&sizeLimit=".$options['sizeLimit'];
        try
        {
            $res=$this->Request2();
            return $res;
        }catch (\think\Exception $e)
        {
            dump($e->getMessage());
        }
    }
    /**
     * 单聊云端历史消息查询
     * 接口描述
     * 初始化队列查询存储在网易云通信服务器中的单人聊天历史消息，只能查询在保存时间范围内的消息
     *跟据时间段查询点对点消息，每次最多返回100条；
     *不提供分页支持，第三方需要跟据时间段来查询。
     * @param array $options
     * @param string from 发送者accid
     * @param long to接收者accid
     * @param String begintime 开始时间，ms
     * @param String endtime 截止时间，ms
     * @param int limit 本次查询的消息条数上限(最多100条),小于等于0，或者大于100，会提示参数错误
     * @param int reverse 1按时间正序排列，2按时间降序排列。其它返回参数414错误.默认是按降序排列
     * @return string $res
     */
    public function querySessionMsg($options)
    {
        $this->url="https://api.netease.im/nimserver/history/querySessionMsg.action";
        $this->string="begintime=".$options['begintime']."&endtime=".$options['endtime'].
        "&from=".$options['from'].
        "&to=".$options['to'].
        "&limit=".$options['limit'];
        try
        {
            $res=$this->Request2();
            return $res;
        }catch (\think\Exception $e)
        {
            dump($e->getMessage());
        }
    }
    /**
     * 群聊云端历史消息查询
     * 接口描述
     * 查询存储在网易云通信服务器中的群聊天历史消息，只能查询在保存时间范围内的消息
     *跟据时间段查询群消息，每次最多返回100条；
     * 不提供分页支持，第三方需要跟据时间段来查询。
     * @param array $options
     * @param string tid 群id
     * @param String accid 查询用户对应的accid.
     * @param String begintime 开始时间，ms
     * @param String endtime 截止时间，ms
     * @param int limit 本次查询的消息条数上限(最多100条),小于等于0，或者大于100，会提示参数错误
     * @param int reverse 1按时间正序排列，2按时间降序排列。其它返回参数414错误.默认是按降序排列
     * @return string $res
     */
    public function queryTeamMsg($options)
    {
        $this->url="https://api.netease.im/nimserver/history/queryTeamMsg.action";
        $this->string="begintime=".$options['begintime']."&endtime=".$options['endtime'].
        "&tid=".$options['tid'].
        "&accid=".$options['accid'].
        "&limit=".$options['limit'];
        try
        {
            $res=$this->Request2();
            return $res;
        }catch (\think\Exception $e)
        {
            dump($e->getMessage());
        }
    }
    /**
     * 聊天室云端历史消息查询
     * 接口描述
     * 1.此接口有频控限制，每分钟可调用不超过1200次
     * @param array $options
     * @param long roomid 聊天室id
     * @param String accid 用户账号
     * @param long timetag 查询的时间戳锚点，13位。reverse=1时timetag为起始时间戳，reverse=2时timetag为终止时间戳
     * @param int limit 本次查询的消息条数上限(最多100条),小于等于0，或者大于200，会提示参数错误
     * @param int reverse 1按时间正序排列，2按时间降序排列。其它返回参数414错误.默认是按降序排列
     * @return string $res
     */
    public function queryChatroomMsg($options)
    {
        $this->url="https://api.netease.im/nimserver/history/queryChatroomMsg.action";
        $this->string="roomid=".$options['roomid'].
        "&accid=".$options['accid'].
        "&timetag=".$options['timetag'].
        "&limit=".$options['limit'].
        "&reverse=".$options['reverse'];
        try
        {
            $res=$this->Request2();
            return $res;
        }catch (\think\Exception $e)
        {
            dump($e->getMessage());
        }
    }
    /**
     * 删除聊天室云端历史消息
     */
    public function deleteHistoryMessage($options)
    {
        $this->url="https://api.netease.im/nimserver/chatroom/deleteHistoryMessage.action";
        $this->string="roomid=".$options['roomid'].
        "&fromAcc=".$options['fromAcc'].
        "&msgTimetag=".$options['msgTimetag'];
        try 
        {
            $res=$this->Request2();
            return $res;
        }catch (\think\Exception $e)
        {
            dump($e->getMessage());
        }
    }
    /**
     *   用户登录登出事件记录查询
     *   接口描述
     *   1.跟据时间段查询用户的登录登出记录，每次最多返回100条。
     *   2.不提供分页支持，第三方需要跟据时间段来查询。
     */
    public function queryUserEvents($options)
    {
        $this->url="https://api.netease.im/nimserver/history/queryUserEvents.action";
        $this->string="accid=".$options['accid'].
        "&begintime=".$options['begintime'].
        "&endtime=".$options['endtime'].
        "&limit=".$options['limit'];
        try
        {
            $res=$this->Request2();
            return $res;
        }catch (\think\Exception $e)
        {
            dump($e->getMessage());
        }
    }
    /**
     * 删除音视频/白板服务器录制文件
     */
    public function deleteMediaFile($options)
    {
        $this->url="https://api.netease.im/nimserver/history/deleteMediaFile.action";
        $this->string="channelid=".$options['channelid'];
        try 
        {
           $res=$this->Request2();
           return $res;
        }catch (\think\Exception $e)
        {
            dump($e->getMessage());
        }
    }
}
